<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection">
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="handleReport(record)"/>
      </template>
      <!--字段回显插槽-->
      <template v-slot:bodyCell="{ column, record, index, text }">
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <ReportKpiModal @register="registerModal" @success="handleSuccess"></ReportKpiModal>
  </div>
</template>

<script lang="ts" name="report_kpi-reportKpi" setup>
  import {reactive,} from 'vue';
  import {BasicTable,TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import ReportKpiModal from './components/ReportKpiModal.vue'
  import {columns, searchFormSchema,} from './ReportKpi.data';
  import {getReportKpiList, ReportAction} from './ReportKpi.api';
  import { getDateByPicker } from '/@/utils';
  import {receiveTask} from "@/views/tobedone/Tobedone.api";
  //日期个性化选择
  const fieldPickers = reactive({
  });
  const queryParam = reactive<any>({});
  //注册model
  const [registerModal, {openModal}] = useModal();
  //注册table数据
  const {tableContext } = useListPage({
      tableProps:{
           title: '汇报年度关键指标',
           api: getReportKpiList,
           columns,
           canResize:true,
           formConfig: {
              // labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
            beforeFetch: (params) => {
              if (params && fieldPickers) {
                for (let key in fieldPickers) {
                  if (params[key]) {
                    params[key] = getDateByPicker(params[key], fieldPickers[key]);
                  }
                }
              }
              return Object.assign(params, queryParam);
            },
      }
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext

   /**
    * 编辑事件
    */
  function handleEdit(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: true,
     });
   }
   /**
    * 详情
   */
  function handleDetail(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: false,
     });
   }

   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }
   /**
      * 操作栏
      */
  function handleReport(record){
       return [
         {
           label: '汇报',
           onClick: handleEdit.bind(null, record),
           auth: 'report_kpi:yx_report_kpi:report'
         },
         {
           label: '详情',
           onClick: handleDetail.bind(null, record),
         }
       ]
   }

  /*
  * 汇报事件
  * */
  // async function handleReportAction(record) {
  //   await ReportAction({id: record.id}, handleSuccess);
  // }






</script>

<style lang="less" scoped>
  :deep(.ant-picker),:deep(.ant-input-number){
    width: 100%;
  }
</style>
